Get the last part before a specified character¶
S.rsplit(‘/’, 1)[0]
Get the last part of a string before a specified character.
S = 'https://www.w3resource.com/python-exercises/string'
print(S.rsplit('/', 1)[0])
print(S.rsplit('-', 1)[0])
Output:
https://www.w3resource.com/python-exercises
https://www.w3resource.com/python